package zuoye;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolDemo03 {
    public static void main(String[] args) {
//最多可执行四个任务
        ThreadPoolExecutor pool =
                new ThreadPoolExecutor(1
                        ,3,20
                        , TimeUnit.SECONDS,new ArrayBlockingQueue<>(1)
                        ,Executors.defaultThreadFactory(),new ThreadPoolExecutor.CallerRunsPolicy());
        //提交五个任务
        for (int i=0;i<5;i++){
            pool.submit(() -> {
                System.out.println(Thread.currentThread().getName()+"执行了任务。。。");
            });
        }
    }

}

